<?php
$r_url = "admin.php?file=userwj";
#[判断权限]
if($_SESSION["admin"]["typer"] != "system" && !$QG_AP["users"])
{
	Error("对不起，您没有权限操作当前功能","admin.php?file=index");
}
if($sysact == "add" || $sysact == "modify")
{
	if($sysAct == "modify")
	{
		$id = intval($id);
		if(!$id)
		{
			Error("操作非法！","admin.php?file=userwj&act=list");
		}
		$rs = $DB->qgGetOne("SELECT * FROM ".$prefix."gen WHERE id='".$id."'");
		$rsa = $DB->qgGetOne("SELECT ge_name FROM ".$prefix."m_gen WHERE id='".$rs[g_gid]."'");
		$rsb = $DB->qgGetOne("SELECT c_name FROM ".$prefix."city WHERE c_id='".$rs[g_cid]."'");
		$rsc = $DB->qgGetOne("SELECT p_nickname FROM ".$prefix."player_info WHERE u_id='".$rs[g_uid]."'");
		$rsd1 = $DB->qgGetOne("SELECT g_name FROM ".$prefix."genequip WHERE g_id='".$id."' AND `g_style` LIKE '武器' ");
		$rsd2 = $DB->qgGetOne("SELECT g_name FROM ".$prefix."genequip WHERE g_id='".$id."' AND `g_style` LIKE '铠甲' ");
		$rsd3 = $DB->qgGetOne("SELECT g_name FROM ".$prefix."genequip WHERE g_id='".$id."' AND `g_style` LIKE '兵符' ");
		$rsd4 = $DB->qgGetOne("SELECT g_name FROM ".$prefix."genequip WHERE g_id='".$id."' AND `g_style` LIKE '书藉' ");
		$rsd5 = $DB->qgGetOne("SELECT g_name FROM ".$prefix."genequip WHERE g_id='".$id."' AND `g_style` LIKE '坐骑' ");
	}
}
elseif($sysact == "viewok")
{
	$id = intval($id);
	$msg = $STR->safe($_POST);
	if(!$msg["ge_name"])
	{
		Error("武将名不能为空",$r_url."&act=".($id ? "modify" : "add")."&id=".$id);
	}
	if($id)
	{
		$rs = $DB->qgGetOne("SELECT * FROM ".$prefix."gen WHERE id='".$id."'");
		$sql = "UPDATE ".$prefix."gen SET g_grade='".$msg["g_grade"]."',g_power='".$msg["g_power"]."',g_commend='".$msg["g_commend"]."',g_intellect='".$msg["g_intellect"]."',g_command='".$msg["g_command"]."',g_fealty='".$msg["g_fealty"]."',g_name='".$msg["g_name"]."' WHERE id='".$id."'";
		$DB->qgQuery($sql);
		$r_url = $_SESSION["return_url"] ? $_SESSION["return_url"] : $r_url."&act=list";
		Error("武将信息更新成功",$r_url);
	}
	else
	{/*
		$sql = "SELECT username FROM ".$prefix."gen WHERE username='".$msg["username"]."'";
		$rschk = $DB->qgGetOne($sql);
		if($rschk)
		{
			Error("会员账号 ".$msg["username"]." 已经存在",$r_url."&act=add");
		}
		$password = $msg["password"] ? md5($rs["password"]) : md5("123456");
		$sql = "INSERT INTO ".$prefix."gen(id,username,password,email,current_money,total_money,status,handset,question,answer,reg_time,login_ip,reg_ip,last_time,marker,off) VALUES('".$msg["username"]."','".$msg["username"]."','".$msg["realname"]."','".$password."','".$msg["email"]."','".$msg["phone"]."','".$msg["address"]."','".$msg["zipcode"]."','".$system_time."')";
		$DB->qgQuery($sql);*/
		Error("功能未开放");
	}
}
elseif($sysact == "delete")
{
	$r_url = $_SESSION["return_url"] ? $_SESSION["return_url"] : $r_url."&act=list";
	$id = intval($id);
	if(!$id)
	{
		Error("操作非法",$r_url);
	}
	$sql = "DELETE FROM ".$prefix."gen WHERE id='".$id."'";
	$DB->qgQuery($sql);
	Error("会员信息删除成功",$r_url);
}
elseif($act == "list")
{
	$page_url = "admin.php?file=userwj&act=list";
	$psize = 20;
	$pageid = intval($pageid);
	$offset = $pageid>0 ? ($pageid-1)*$psize : 0;
	$condition = "WHERE 1";
	$keywords = SafeHtml($keywords);
	$stype = SafeHtml($stype);
	if($keywords)
	{
		if($stype == "id")
		{
			$condition .= " AND id LIKE '%".$keywords."%'";
		}
		elseif($stype == "realname")
		{
			$condition .= " AND realname LIKE '%".$keywords."%'";
		}
		elseif($stype == "email")
		{
			$condition .= " AND email LIKE '%".$keywords."%'";
		}
		elseif($stype == "address")
		{
			$condition .= " AND address LIKE '%".$keywords."%'";
		}
		elseif($stype == "phone")
		{
			$condition .= " AND phone LIKE '%".$keywords."%'";
		}
		else
		{
			$condition .= " AND username LIKE '%".$keywords."%'";
		}
		$page_url .= "&stype=".rawurlencode($stype)."&keywords=".rawurlencode($keywords);
	}
	$count = $DB->qg_count("SELECT count(id) FROM ".$prefix."gen ".$condition);
	$pagelist = page($page_url,$count,$psize,$pageid);#[获取页数信息]
	$rslist = $DB->qgGetAll("SELECT * FROM ".$prefix."gen ".$condition." ORDER BY id DESC LIMIT ".$offset.",".$psize);
}
elseif($act == "listm")
{
	$page_url = "admin.php?file=userwj&act=listm";
	$psize = 30;
	$pageid = intval($pageid);
	$offset = $pageid>0 ? ($pageid-1)*$psize : 0;
	$condition = "WHERE 1";
	$keywords = SafeHtml($keywords);
	$stype = SafeHtml($stype);
	if($keywords)
	{
		if($stype == "id")
		{
			$condition .= " AND id LIKE '%".$keywords."%'";
		}
		elseif($stype == "realname")
		{
			$condition .= " AND realname LIKE '%".$keywords."%'";
		}
		elseif($stype == "email")
		{
			$condition .= " AND email LIKE '%".$keywords."%'";
		}
		elseif($stype == "address")
		{
			$condition .= " AND address LIKE '%".$keywords."%'";
		}
		elseif($stype == "phone")
		{
			$condition .= " AND phone LIKE '%".$keywords."%'";
		}
		else
		{
			$condition .= " AND username LIKE '%".$keywords."%'";
		}
		$page_url .= "&stype=".rawurlencode($stype)."&keywords=".rawurlencode($keywords);
	}
	$count = $DB->qg_count("SELECT count(id) FROM ".$prefix."gen ".$condition);
	$pagelist = page($page_url,$count,$psize,$pageid);#[获取页数信息]
	$rslist = $DB->qgGetAll("SELECT * FROM ".$prefix."gen ".$condition." ORDER BY current_money DESC LIMIT ".$offset.",".$psize);
}
elseif($act == "listt")
{
	$page_url = "admin.php?file=userwj&act=listt";
	$psize = 30;
	$pageid = intval($pageid);
	$offset = $pageid>0 ? ($pageid-1)*$psize : 0;
	$condition = "WHERE 1";
	$keywords = SafeHtml($keywords);
	$stype = SafeHtml($stype);
	if($keywords)
	{
		if($stype == "id")
		{
			$condition .= " AND id LIKE '%".$keywords."%'";
		}
		elseif($stype == "realname")
		{
			$condition .= " AND realname LIKE '%".$keywords."%'";
		}
		elseif($stype == "email")
		{
			$condition .= " AND email LIKE '%".$keywords."%'";
		}
		elseif($stype == "address")
		{
			$condition .= " AND address LIKE '%".$keywords."%'";
		}
		elseif($stype == "phone")
		{
			$condition .= " AND phone LIKE '%".$keywords."%'";
		}
		else
		{
			$condition .= " AND username LIKE '%".$keywords."%'";
		}
		$page_url .= "&stype=".rawurlencode($stype)."&keywords=".rawurlencode($keywords);
	}
	$count = $DB->qg_count("SELECT count(id) FROM ".$prefix."gen ".$condition);
	$pagelist = page($page_url,$count,$psize,$pageid);#[获取页数信息]
	$rslist = $DB->qgGetAll("SELECT * FROM ".$prefix."gen ".$condition." ORDER BY id DESC LIMIT ".$offset.",".$psize);
}
Foot("userwj.qg");
?>